package com.wtwd.campus.service.impl;

import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.DeviceInfo;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.entity.MqPhoneDatas;
import com.wtwd.campus.entity.PhoneData;
import com.wtwd.campus.fjryE15.service.DeviceService;
import com.wtwd.campus.hxy.service.CommandRecordService;
import com.wtwd.campus.service.*;
import com.wtwd.campus.utils.CommandSendUtils;
import com.wtwd.campus.vcom.common.Constant;
import com.wtwd.campus.vcom.entity.VcomRequestRecord;
import com.wtwd.campus.vcom.service.VcomPhoneService;
import com.wtwd.campus.vcom.service.VcomService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * @author mjy
 * @date 2022/11/01
 * @description
 */
@Service("CustomerDealCmdServiceImpl")
public class CustomerDealCmdServiceImpl implements CustomerDealCmdService {


    @Resource
    private CommandRecordService commandRecordService;

    @Resource
    private RedisService redisService;

    @Resource
    private VcomService vcomService;

    @Value("${h5.customerId.ryh5}")
    private Integer ryh5CustomerId;


    @Override
    public MqPhoneDatas getPhoneData(String imei, Integer deviceType, Integer customerId, String type, String commandNumber) {
        if (Constants.VCOM_DEVICE == deviceType) {
            return vcomService.getPhoneData(imei, deviceType, customerId, type, commandNumber);
        }
        return null;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean dealCustomerGetPhoneData(String imei, Integer deviceType, Integer customerId, String type, MqPhoneDatas phoneDatas) {
        if (Constants.VCOM_DEVICE == deviceType) {//如果是vcom设备,取消号码类缓存重发,将之前vcom号码请求指令置为失败处理,并同步数据库号码
            return vcomService.dealCustomerGetPhoneData(imei, deviceType, customerId, type, phoneDatas);
        }
        return false;
    }

    @Override
    public Boolean dealCustomerPolygonFence(MqLocationData mqLocationData, DeviceInfo deviceInfo, String address, long locationTime) {
        if (deviceInfo.getDeviceType() != null && deviceInfo.getCustomerId() != null) {
            if (deviceInfo.getDeviceType().equals(Constants.VCOM_DEVICE)){
                vcomService.dealCustomerPolygonFence(mqLocationData,deviceInfo,address,locationTime);
            }
        } else {//平台设备处理暂时不做

        }
        return false;
    }


    @Override
    public CommandRecordService getCommandRecordService() {
        return commandRecordService;
    }

    @Override
    public RedisService getRedis() {
        return redisService;
    }

}
